const common = require('../../utils/common')
const { shopDelete } = require('../../services/stores')
const store = require('../../utils/store')
Page({
  data: {
    detail: {}
  },
  onLoad: function ({ data }) {
    if (!data) return
    this.initData(JSON.parse(data))
  },
  initData: function (data) {
    this.setData({
      detail: { ...this.data.detail, ...data }
    })
  },
  previewImg: function () {
    if (!this.data.detail.businessLicense) {
      common.showToast('你还没有上传营业执照')
      return
    }
    wx.previewImage({
      urls: [this.data.detail.businessLicense]
    })
  },
  shopDelete: function () {
    shopDelete({ shopId: this.data.detail.id }).then(() => {
      common.showToast("删除成功")
      wx.navigateTo({
        url: `/pages/rejected-list/index`
      })
    }).catch((err) => {
      common.log(err)
    })
  },
  goEditShop: function () {
    store.setStore('editStore', this.data.detail)
    wx.navigateTo({
      url: `/pages/new-store/index?edit=1`
    })
  }
})
